﻿using EYangFramewirk.Business.MessageSystem.Interfaces;
using EYangFramework.Domain.Entitys.Entrys;
using EYangFramework.Domain.Entitys.ValueObjects;
using EYangFramework.Domain.Repositorys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EYangFramewirk.Business.MessageSystem.Implementation
{
    public class BLLLinkUser : IBLLLinkUser
    {
        IRepository<LinkUser> RepositoryLinkUser { get; set; }
        IRepository<User> RepositoryUser { get; set; }
        public BLLLinkUser(IRepository<LinkUser> repositoryLinkUser, IRepository<User> repositoryUser)
        {
            this.RepositoryLinkUser = repositoryLinkUser;
            this.RepositoryUser = repositoryUser;
        }
        public bool DeleteLinkUser(Guid id)
        {
            RepositoryLinkUser.Delete(id);
            return true;
        }

        public void Dispose()
        {
            RepositoryLinkUser.DbContext.Dispose();
            RepositoryUser.DbContext.Dispose();
        }

        public List<LinkUser> GetLinkUsers(Guid user)
        {
            var id = user.ToString();
            return RepositoryLinkUser.GetAllList(t => t.User == id);
        }

        public bool InsertLinkUser(LinkUser linkUser)
        {
            RepositoryLinkUser.Insert(linkUser);
            return true;
        }

        public bool UpdateLinkUser(LinkUser linkUser)
        {
            RepositoryLinkUser.Update(linkUser);
            return true;
        }

        public List<User> GetAllUsers()
        {
            return RepositoryUser.GetAllListNoTracking(t => !t.ISDELETE);
        }

        public LinkUser GetCurrentLinkUser(Guid id)
        {
            return RepositoryLinkUser.GetAllList(t => t.ID == id).First();
        }
    }
}
